home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Apple Game Sprockets / More Sprocket Examples 1.0 / GlyphaIV Sources / G4SetUpTakeDown.c < prev    next >
Encoding:
Text File  |  1996-06-12  |  24.4 KB  |  671 lines  |  [TEXT/CWIE]

  1.  
  2. //============================================================================
  3. //----------------------------------------------------------------------------
  4. //                                SetUpTakeDown.c
  5. //----------------------------------------------------------------------------
  6. //============================================================================
  7.  
  8. // The below functions are grouped here becuase they are only called once when…
  9. // Glypha either starts up or quits.
  10.  
  11. #include "G4Externs.h"
  12. #include <Palettes.h>                    // Need "Palettes.h" for the depth calls.
  13. #include <Fonts.h>
  14.  
  15. #define kHandPictID                128        // These are all the resource ID's for…
  16. #define kHandMaskID                129        // the various PICT's were going to…
  17. #define kBackgroundPictID        130        // load up into offscreen pixmaps and…
  18. #define kHelpPictID                131        // offscreen bitmaps.
  19. #define kObeliskPictID            134
  20. #define kPlayerPictID            135
  21. #define kPlayerMaskID            136
  22. #define kNumberPictID            137
  23. #define kIdlePictID                138
  24. #define kEnemyWalkPictID        139
  25. #define kEnemyFlyPictID            140
  26. #define kEnemyWalkMaskID        141
  27. #define kEnemyFlyMaskID            142
  28. #define kFlamePictID            143
  29. #define kEggPictID                144
  30. #define kEggMaskID                145
  31. #define kPlatformPictID            146
  32. #define kEyePictID                147
  33. #define kEyeMaskID                148
  34. #define kObeliskMaskPictID        149
  35. #define kBannerPictID            150
  36.  
  37.  
  38.  
  39. Boolean DoWeHaveColor (void);            // Prototypes to below functions that are…
  40. Boolean DoWeHaveSystem605 (void);        // called locally.  These aren't really…
  41. short WhatsOurDepth (void);                // necessary, but I don't enjoy relying on…
  42. Boolean CanWeDisplay8Bit (GDHandle);    // the compiler to second guess me.
  43. void SwitchToDepth (short, Boolean);
  44.  
  45. void MyInitAttributes( DSpContextAttributes *inAttributes );
  46.  
  47. short        wasDepth;                    // Only global variable defined here.
  48.  
  49. #if GENERATINGPOWERPC
  50.     DSpContextAttributes gTheContextAttributes;
  51.     DSpContextReference gTheContext;
  52. #endif
  53.                                         // Other global variables defined elsewhere.
  54. extern    Rect        mainWindowRect, backSrcRect, workSrcRect, obSrcRect, playerSrcRect;
  55. extern    Rect        numberSrcRect, idleSrcRect, enemyWalkSrcRect, enemyFlySrcRect;
  56. extern    Rect        obeliskRects[4], playerRects[11], numbersSrc[11], numbersDest[11];
  57. extern    Rect        platformRects[6], touchDownRects[6], enemyRects[24], handSrcRect;
  58. extern    Rect        flameSrcRect, flameDestRects[2], flameRects[4], platformCopyRects[9];
  59. extern    Rect        enemyInitRects[5], eggSrcRect, platformSrcRect, helpSrcRect;
  60. extern    Rect        handRects[2], grabZone, eyeSrcRect, bannerSrcRect, eyeRects[4];
  61. extern    GDHandle    thisGDevice;
  62. extern    CGrafPtr    origBackSrcMap, backSrcMap, workSrcMap, obeliskSrcMap, playerSrcMap;
  63. extern    CGrafPtr    numberSrcMap, idleSrcMap, enemyWalkSrcMap, enemyFlySrcMap;
  64. extern    CGrafPtr    flameSrcMap, eggSrcMap, platformSrcMap, helpSrcMap, handSrcMap;
  65. extern    CGrafPtr    eyeSrcMap, bannerSrcMap;
  66. extern    GrafPtr        playerMaskMap, enemyWalkMaskMap, enemyFlyMaskMap, eggMaskMap;
  67. extern    GrafPtr        handMaskMap, eyeMaskMap, obeliskMaskMap;
  68. extern    MenuHandle    appleMenu, gameMenu, optionsMenu;
  69. extern    long        theScore, wasTensOfThousands;
  70. extern    short        numLedges, beginOnLevel, levelOn, livesLeft;
  71. extern    Boolean        quitting, playing, pausing, switchedOut, canPlay, whichList;
  72. extern    Boolean        helpOpen, scoresOpen, openTheScores;
  73.  
  74.  
  75. //==============================================================  Functions
  76. //--------------------------------------------------------------  ToolBoxInit
  77.  
  78. // Here's the first function you ever call in Glypha (or any Mac program for…
  79. // that matter).  The calls herein MUST be called before you do anything else.
  80. // Otherwise, you'll get all sorts of System Errors.
  81.  
  82. void ToolBoxInit (void)
  83. {
  84.     InitGraf(&qd.thePort);        // Initialize QuickDraw variables for our program.
  85.     InitFonts();                // Initialize fonts.
  86.     FlushEvents(everyEvent, 0);    // Clear event queue of any pending events.
  87.     InitWindows();                // Initialize the Window Manager.
  88.     InitMenus();                // Ditto for the Menu Manager.
  89.     TEInit();                    // blah, blah Text Edit.
  90.     InitDialogs(0L);            // blah, blah Dialog Manager.
  91.     InitCursor();                // Set the cursor to the arrow cursor and init.
  92.     
  93.     MaxApplZone();                // Grab application memory.
  94.     
  95.     MoreMasters();                // Allocate a block of master pointers.
  96.     MoreMasters();                // And allocate more.
  97.     MoreMasters();                // And more.
  98.     MoreMasters();                // Hey, lets do it again too.
  99.     
  100.     switchedOut = FALSE;        // We "should" be the foreground app at this time.
  101.     GetDateTime((unsigned long *)&qd.randSeed);        // Randomize random seed.
  102. }
  103.  
  104. //--------------------------------------------------------------  DoWeHaveColor  
  105.  
  106. // Simple function that returns TRUE if we're running on a Mac that…
  107. // is running Color Quickdraw.
  108.  
  109. Boolean DoWeHaveColor (void)
  110. {
  111.     SysEnvRec        thisWorld;
  112.     
  113.     SysEnvirons(2, &thisWorld);        // Call the old SysEnvirons() function.
  114.     return (thisWorld.hasColorQD);    // And return whether it has Color QuickDraw.
  115. }
  116.  
  117. //--------------------------------------------------------------  DoWeHaveSystem605  
  118.  
  119. // Another simple "environment" function.  Returns TRUE if the Mac we're running…
  120. // on has System 6.0.5 or more recent.  (6.0.5 introduced the ability to switch…
  121. // color depths.)
  122.  
  123. Boolean DoWeHaveSystem605 (void)
  124. {
  125.     SysEnvRec        thisWorld;
  126.     Boolean            haveIt;
  127.     
  128.     SysEnvirons(2, &thisWorld);        // Call the old SysEnvirons() function.
  129.     if (thisWorld.systemVersion >= 0x0605)
  130.         haveIt = TRUE;                // Check the System version for 6.0.5…
  131.     else                            // or more recent
  132.         haveIt = FALSE;
  133.     return (haveIt);
  134. }
  135.  
  136. //--------------------------------------------------------------  WhatsOurDepth  
  137.  
  138. // Function returns the current bit depth.  For example, 4 = 16 colors, 8 = 256…
  139. // colors.  Note, this function assumes System 6.0.5 or more recent and Color…
  140. // Quickdraw capable.  You should haved called the previous two functions before…
  141. // attempting this call.
  142.  
  143. short WhatsOurDepth (void)
  144. {
  145.     short            thisDepth;
  146.     char            wasState;
  147.     
  148.     if (thisGDevice != 0L)                            // Make sure we have device handle.
  149.     {
  150.         wasState = HGetState((Handle)thisGDevice);    // Remember the handle's state.
  151.         HLock((Handle)thisGDevice);                    // Lock the device handle down.
  152.                                                     // Get it's depth (pixelSize).
  153.         thisDepth = (**(**thisGDevice).gdPMap).pixelSize;
  154.         HSetState((Handle)thisGDevice, wasState);    // Restore handle's state.
  155.     }
  156.     else
  157.         RedAlert("\pUnknown Error.");                // Post generic error message.
  158.     
  159.     return (thisDepth);                                // Return screen depth.
  160. }
  161.  
  162. //--------------------------------------------------------------  CanWeDisplay8Bit  
  163.  
  164. // Simple function that returns TRUE if the current device (monitor) is…
  165. // capable of displaying 256 colors (or grays).  This function, the one above,…
  166. // and many following functions assume we have System 6.0.5 or more recent and…
  167. // are capable of Color QuickDraw.
  168.  
  169. Boolean CanWeDisplay8Bit (GDHandle theDevice)
  170. {
  171.     short        canDepth;
  172.     Boolean        canDo;
  173.     
  174.     canDo = FALSE;        // Assume intially that we can't display 8 bit.
  175.                         // Call HasDepth() to see if monitor supports 8 bit.
  176.     canDepth = HasDepth(theDevice, 8, 1, 0);
  177.     if (canDepth != 0)    // If HasDepth() returned anything other than 0…
  178.         canDo = TRUE;    // we can indeed switch it to 8 bit.
  179.     
  180.     return (canDo);        // Return the result.
  181. }
  182.  
  183. //--------------------------------------------------------------  SwitchToDepth
  184.  
  185. // This handy function forces the device (monitor) in question to switch…
  186. // to a specific depth.  We'll call this function if we need to switch to…
  187. // 8-bit (256 colors).  We should have called the above function first in…
  188. // order to be sure that we CAN in fact switch this monitor to 8-bit.
  189.  
  190. void SwitchToDepth (short newDepth, Boolean doColor)
  191. {
  192.     OSErr            theErr;
  193.     short            colorFlag;
  194.     char            tagByte;
  195.     
  196.     if (doColor)                    // We can switch to either colors or grays.
  197.         colorFlag = 1;
  198.     else
  199.         colorFlag = 0;
  200.     
  201.     if (thisGDevice != 0L)            // Make sure we have a device.
  202.     {                                // Remember handle's state (as usual).
  203.         tagByte = HGetState((Handle)thisGDevice);
  204.         HLock((Handle)thisGDevice);    // Lock it.
  205.                                     // Call SetDepth() (System 6.0.5 or more recent).
  206.         theErr = SetDepth(thisGDevice, newDepth, 1, colorFlag);
  207.                                     // Restore handle's state.
  208.         HSetState((Handle)thisGDevice, tagByte);
  209.         if (theErr != noErr)        // If call failed, go to error dialog.
  210.             RedAlert("\pUnknown Error.");
  211.     }
  212.     else                            // Call error dialog if no device handle.
  213.         RedAlert("\pUnknown Error.");
  214. }
  215.  
  216. //--------------------------------------------------------------  CheckEnvirons
  217.  
  218. // This is the "wrapper" function that calls all the above functions.
  219. // After calling ToolBoxInit(), Glypha will call this function to see…
  220. // if the current Mac we're running on is capable of running Glypha.
  221.  
  222. void CheckEnvirons (void)
  223. {    
  224. #if GENERATINGPOWERPC
  225.     OSStatus theError;
  226.     
  227.     // DSp_SetDebugMode( true );
  228.     
  229.     // 640x480x8
  230.     MyInitAttributes( &gTheContextAttributes );
  231.     gTheContextAttributes.displayWidth            = 640;
  232.     gTheContextAttributes.displayHeight            = 480;
  233.     gTheContextAttributes.colorNeeds            = kDSpColorNeeds_Require;
  234.     gTheContextAttributes.backBufferDepthMask    = kDSpDepthMask_8;
  235.     gTheContextAttributes.displayDepthMask        = kDSpDepthMask_8;
  236.     gTheContextAttributes.backBufferBestDepth    = 8;
  237.     gTheContextAttributes.displayBestDepth        = 8;
  238.     theError = DSpFindBestContext( &gTheContextAttributes, &gTheContext );
  239.     if( theError )
  240.         RedAlert("\pUnable to find a suitable device\n");
  241.     
  242.     FindOurDevice();
  243.     
  244. #else        
  245.     if (!DoWeHaveColor())            // We absolutely need Color QuickDraw.
  246.         RedAlert("\pGlypha IV only runs in 256 colors.");
  247.     
  248.     if (!DoWeHaveSystem605())        // We absolutely need System 6.0.5. or more recent.
  249.         RedAlert("\pGlypha IV requires System 6.0.5 or better to run.");
  250.     
  251.     FindOurDevice();
  252.     
  253.     wasDepth = WhatsOurDepth();        // Find out our monitor's depth.
  254.     if (wasDepth != 8)                // If it's not 8-bit we'll need to switch depths.
  255.     {                                // Test 1st to see if monitor capable of 8-bit.
  256.         if (CanWeDisplay8Bit(thisGDevice))
  257.             SwitchToDepth(8, TRUE);    // If so, switch to 256 colors.
  258.         else                        // If not, we have to quit.
  259.             RedAlert("\pGlypha IV only runs in 256 colors.");
  260.     }
  261. #endif
  262. }
  263.  
  264. //--------------------------------------------------------------  OpenMainWindow
  265.  
  266. // This is a simple function that merely opens up a large black window and…
  267. // centers it in the monitor.  It assumes a 'WIND' (window) resource, which if you…
  268. // look at the resource file in ResEdit, you'll find it also has a 'WCTB'…
  269. // (window color table) resource.  The 'WCTB' resource specifies a content…
  270. // color of black - thus this window comes up black.
  271.  
  272. void OpenMainWindow (void)
  273. {
  274. #if GENERATINGPOWERPC
  275.     OSStatus theError;
  276.     
  277.     theError = DSpContext_Reserve( gTheContext, &gTheContextAttributes );
  278.     if( theError )
  279.         RedAlert("\pUnable to create the display!");
  280.  
  281.     theError = DSpContext_FadeGammaOut( NULL, NULL );    
  282.     if( theError )
  283.         RedAlert("\pUnable to fade the display!");
  284.  
  285.     theError = DSpContext_SetState( gTheContext, kDSpContextState_Active );
  286.     if( theError )
  287.         RedAlert("\pUnable to set the display!");
  288.  
  289.     // this is our fake main window, it is really a CGrafPtr so don't try to
  290.     // use it with the Window Manager, and DON'T try to dispose of it.  In
  291.     // a page flipping scenario, it would change with every call to SwapDisplayBuffers(),
  292.     // but since Glypha is designed to work with DoubleBuffering we know the front
  293.     // buffer will remain the same.
  294.     SetRect(&mainWindowRect, 0, 0, 640, 480);            // Our window size.
  295.     
  296. #else
  297.     SetRect(&mainWindowRect, 0, 0, 640, 460);            // Our window size.
  298.     mainWindow = GetNewCWindow(128, 0L, kPutInFront);    // Load window from resource.
  299.                                                         // Make it the right size.
  300.     SizeWindow((GrafPtr)mainWindow, mainWindowRect.right - mainWindowRect.left, 
  301.             mainWindowRect.bottom - mainWindowRect.top, FALSE);
  302.                                                         // Center the window.
  303.     MoveWindow((GrafPtr)mainWindow, (qd.screenBits.bounds.right - 640) / 2, 
  304.             ((qd.screenBits.bounds.bottom - 480) / 2) + LMGetMBarHeight(), TRUE);
  305.     ShowWindow((GrafPtr)mainWindow);                    // Now display it.
  306.     SetPort((GrafPtr)mainWindow);                        // Make its port current.
  307.     ClipRect(&mainWindowRect);                            // Set its clip region.
  308.     CopyRgn(mainWindow->clipRgn, mainWindow->visRgn);    // Set its visRgn.
  309.     ForeColor(blackColor);                                // Set its pen color to black.
  310.     BackColor(whiteColor);                                // Set background color white.
  311. #endif
  312. }
  313.  
  314. //--------------------------------------------------------------  InitMenubar
  315.  
  316. // This function loads up the menus and displays the menu bar.
  317.  
  318. void InitMenubar (void)
  319. {
  320.     appleMenu = GetMenu(128);        // Get the Apple menu (About…).
  321.     if (appleMenu == 0L)            // See that it loaded okay.
  322.         RedAlert("\pCouldn't Load Menus Error");
  323.     AddResMenu(appleMenu, 'DRVR');    // Add Desk Accesories.
  324.     InsertMenu(appleMenu, 0);        // Add to menu bar.
  325.     
  326.     gameMenu = GetMenu(129);        // Next load the Game menu.
  327.     if (gameMenu == 0L)                // Make sure it loaded as well.
  328.         RedAlert("\pCouldn't Load Menus Error");
  329.     InsertMenu(gameMenu, 0);        // And add it next to the menu bar.
  330.     
  331.     optionsMenu = GetMenu(130);        // Finally load the Options menu.
  332.     if (optionsMenu == 0L)
  333.         RedAlert("\pCouldn't Load Menus Error");
  334.     InsertMenu(optionsMenu, 0);        // And insert it.
  335.     
  336.     DrawMenuBar();                    // Now display the menu bar.
  337. }
  338.  
  339. //--------------------------------------------------------------  InitVariables
  340.  
  341. // This function is called only once.  It initializes all the global variables…
  342. // used by Glypha.  It may not in fact be necessary to initialize many of these…
  343. // (your compiler should ensure that all globals are set to zero when your app…
  344. // launches), but it's a good idea to NEVER TRUST YOUR COMPILER.
  345.  
  346. void InitVariables (void)
  347. {
  348.     short        i;
  349.     OSStatus    theError;
  350.         
  351.     quitting = FALSE;    // I won't describe every one of these, many are…
  352.     playing = FALSE;    // self explanatory.  Suffice it to say that first…
  353.     pausing = FALSE;    // I'm initializing all the Boolean variables.
  354.     canPlay = FALSE;
  355.     whichList = TRUE;
  356.     helpOpen = FALSE;
  357.     scoresOpen = FALSE;
  358.     openTheScores = FALSE;
  359.     
  360.     numLedges = 3;                    // Number of ledges in the "arena".
  361.     beginOnLevel = 1;                // First level to begin playing.
  362.     levelOn = 0;                    // Level number player is on.
  363.     livesLeft = kInitNumLives;        // Number of player lives.
  364.     theScore = 0L;                    // Player's score (notice it's a long!).
  365.     wasTensOfThousands = 0L;        // For tracking when player gets an extra life.
  366.     GenerateLightning(320, 240);    // Initialize a lightning bolt.
  367.     
  368.     backSrcRect = mainWindowRect;    // Create background offscreen pixmap.
  369.     ZeroRectCorner(&backSrcRect);
  370.     backSrcMap = 0L;
  371.     CreateOffScreenPixMap(&backSrcRect, &backSrcMap);
  372.     LoadGraphic(kBackgroundPictID);
  373.     
  374.     origBackSrcMap = 0L;
  375.     CreateOffScreenPixMap(&backSrcRect, &origBackSrcMap);
  376.     LoadGraphic(kBackgroundPictID);
  377.  
  378. #if GENERATINGPOWERPC
  379.     theError = DSpContext_GetBackBuffer( gTheContext, kDSpBufferKind_Normal, &workSrcMap );
  380.     if( theError )
  381.     {
  382.         DSpContext_Release( gTheContext );
  383.         RedAlert("\pUnable to get back buffer");
  384.     }
  385. #else    
  386.     workSrcRect = mainWindowRect;    // Create "work" offscreen pixmap.
  387.     ZeroRectCorner(&workSrcRect);
  388.     workSrcMap = 0L;
  389.     CreateOffScreenPixMap(&workSrcRect, &workSrcMap);
  390. #endif
  391.  
  392.     SetRect(&obSrcRect, 0, 0, 20, 418);
  393.     obeliskSrcMap = 0L;                // Create pixmap to hold "obelisk" graphics.
  394.     CreateOffScreenPixMap(&obSrcRect, &obeliskSrcMap);
  395.     LoadGraphic(kObeliskPictID);
  396.     SetRect(&obeliskRects[0], 0, 0, 20, 209);
  397.     OffsetRect(&obeliskRects[0], 0, 0);
  398.     SetRect(&obeliskRects[1], 0, 0, 20, 209);
  399.     OffsetRect(&obeliskRects[1], 0, 209);
  400.     SetRect(&obeliskRects[2], 0, 0, 20, 209);
  401.     OffsetRect(&obeliskRects[2], 161, 250);
  402.     SetRect(&obeliskRects[3], 0, 0, 20, 209);
  403.     OffsetRect(&obeliskRects[3], 457, 250);
  404.     
  405.     obeliskMaskMap = 0L;                // Create pixmap to hold "obelisk" mask
  406.     CreateOffScreenBitMap(&obSrcRect, &obeliskMaskMap);
  407.     LoadGraphic(kObeliskMaskPictID);
  408.     
  409.     
  410.     SetRect(&playerSrcRect, 0, 0, 48, 436);
  411.     playerSrcMap = 0L;                // Create pixmap to hold "player" graphics.
  412.     CreateOffScreenPixMap(&playerSrcRect, &playerSrcMap);
  413.     LoadGraphic(kPlayerPictID);
  414.     playerMaskMap = 0L;
  415.     CreateOffScreenBitMap(&playerSrcRect, &playerMaskMap);
  416.     LoadGraphic(kPlayerMaskID);
  417.     
  418.     SetRect(&enemyWalkSrcRect, 0, 0, 48, 576);
  419.     enemyWalkSrcMap = 0L;            // Create pixmap to hold "enemy" graphics.
  420.     CreateOffScreenPixMap(&enemyWalkSrcRect, &enemyWalkSrcMap);
  421.     LoadGraphic(kEnemyWalkPictID);
  422.     enemyWalkMaskMap = 0L;
  423.     CreateOffScreenBitMap(&enemyWalkSrcRect, &enemyWalkMaskMap);
  424.     LoadGraphic(kEnemyWalkMaskID);
  425.     SetRect(&enemyFlySrcRect, 0, 0, 64, 480);
  426.     enemyFlySrcMap = 0L;
  427.     CreateOffScreenPixMap(&enemyFlySrcRect, &enemyFlySrcMap);
  428.     LoadGraphic(kEnemyFlyPictID);
  429.     enemyFlyMaskMap = 0L;
  430.     CreateOffScreenBitMap(&enemyFlySrcRect, &enemyFlyMaskMap);
  431.     LoadGraphic(kEnemyFlyMaskID);
  432.     for (i = 0; i < 12; i++)
  433.     {                                // Set up enemy source rectangles.
  434.         SetRect(&enemyRects[i], 0, 0, 48, 48);
  435.         OffsetRect(&enemyRects[i], 0, 48 * i);
  436.     }
  437.     for (i = 0; i < 12; i++)
  438.     {
  439.         SetRect(&enemyRects[i + 12], 0, 0, 64, 40);
  440.         OffsetRect(&enemyRects[i + 12], 0, 40 * i);
  441.     }
  442.     SetRect(&enemyInitRects[0], 0, 0, 48, 1);
  443.     OffsetRect(&enemyInitRects[0], 72, 284);
  444.     SetRect(&enemyInitRects[1], 0, 0, 48, 1);
  445.     OffsetRect(&enemyInitRects[1], 520, 284);
  446.     SetRect(&enemyInitRects[2], 0, 0, 48, 1);
  447.     OffsetRect(&enemyInitRects[2], 72, 105);
  448.     SetRect(&enemyInitRects[3], 0, 0, 48, 1);
  449.     OffsetRect(&enemyInitRects[3], 520, 105);
  450.     SetRect(&enemyInitRects[4], 0, 0, 48, 1);
  451.     OffsetRect(&enemyInitRects[4], 296, 190);
  452.     
  453.     SetRect(&eggSrcRect, 0, 0, 24, 24);
  454.     eggSrcMap = 0L;                    // Create pixmap to hold "egg" graphics.
  455.     CreateOffScreenPixMap(&eggSrcRect, &eggSrcMap);
  456.     LoadGraphic(kEggPictID);
  457.     eggMaskMap = 0L;
  458.     CreateOffScreenBitMap(&eggSrcRect, &eggMaskMap);
  459.     LoadGraphic(kEggMaskID);
  460.  
  461.     bannerSrcMap = 0L;                    // Create pixmap to hold banner graphics.
  462.     SetRect(&bannerSrcRect,0,0,1280,20);
  463.     CreateOffScreenPixMap(&bannerSrcRect, &bannerSrcMap);
  464.     LoadGraphic(kBannerPictID);
  465.     
  466.     SetRect(&eyeSrcRect, 0, 0, 48, 124);
  467.     eyeSrcMap = 0L;                    // Create pixmap to hold "eye" graphics.
  468.     CreateOffScreenPixMap(&eyeSrcRect, &eyeSrcMap);
  469.     LoadGraphic(kEyePictID);
  470.     eyeMaskMap = 0L;
  471.     CreateOffScreenBitMap(&eyeSrcRect, &eyeMaskMap);
  472.     LoadGraphic(kEyeMaskID);
  473.     for (i = 0; i < 4; i++)
  474.     {
  475.         SetRect(&eyeRects[i], 0, 0, 48, 31);
  476.         OffsetRect(&eyeRects[i], 0, i * 31);
  477.     }
  478.     
  479.     SetRect(&handSrcRect, 0, 0, 56, 114);
  480.     handSrcMap = 0L;                // Create pixmap to hold "mummy hand" graphics.
  481.     CreateOffScreenPixMap(&handSrcRect, &handSrcMap);
  482.     LoadGraphic(kHandPictID);
  483.     handMaskMap = 0L;
  484.     CreateOffScreenBitMap(&handSrcRect, &handMaskMap);
  485.     LoadGraphic(kHandMaskID);
  486.     SetRect(&handRects[0], 0, 0, 56, 57);
  487.     OffsetRect(&handRects[0], 0, 0);
  488.     SetRect(&handRects[1], 0, 0, 56, 57);
  489.     OffsetRect(&handRects[1], 0, 57);
  490.     SetRect(&grabZone, 0, 0, 96, 108);
  491.     OffsetRect(&grabZone, 48, 352);
  492.     
  493.     SetRect(&idleSrcRect, 0, 0, 48, 48);
  494.     idleSrcMap = 0L;                // Create pixmap to hold "shielded player".
  495.     CreateOffScreenPixMap(&idleSrcRect, &idleSrcMap);
  496.     LoadGraphic(kIdlePictID);
  497.     
  498.     SetRect(&flameSrcRect, 0, 0, 16, 64);
  499.     flameSrcMap = 0L;                // Create pixmap to hold "torch" graphics.
  500.     CreateOffScreenPixMap(&flameSrcRect, &flameSrcMap);
  501.     LoadGraphic(kFlamePictID);
  502.     SetRect(&flameDestRects[0], 0, 0, 16, 16);
  503.     OffsetRect(&flameDestRects[0], 87, 325);
  504.     SetRect(&flameDestRects[1], 0, 0, 16, 16);
  505.     OffsetRect(&flameDestRects[1], 535, 325);
  506.     for (i = 0; i < 4; i++)
  507.     {
  508.         SetRect(&flameRects[i], 0, 0, 16, 16);
  509.         OffsetRect(&flameRects[i], 0, i * 16);
  510.     }
  511.     
  512.     SetRect(&numberSrcRect, 0, 0, 8, 121);
  513.     numberSrcMap = 0L;                // Create pixmap to hold "score numbers".
  514.     CreateOffScreenPixMap(&numberSrcRect, &numberSrcMap);
  515.     LoadGraphic(kNumberPictID);
  516.     for (i = 0; i < 11; i++)
  517.     {
  518.         SetRect(&numbersSrc[i], 0, 0, 8, 11);
  519.         OffsetRect(&numbersSrc[i], 0, 11 * i);
  520.     }
  521.     SetRect(&numbersDest[0], 0, 0, 8, 11);    // # of lives digit 1
  522.     OffsetRect(&numbersDest[0], 229, 443);
  523.     SetRect(&numbersDest[1], 0, 0, 8, 11);    // # of lives digit 2
  524.     OffsetRect(&numbersDest[1], 237, 443);
  525.     SetRect(&numbersDest[2], 0, 0, 8, 11);    // score digit 1
  526.     OffsetRect(&numbersDest[2], 293, 443);
  527.     SetRect(&numbersDest[3], 0, 0, 8, 11);    // score digit 2
  528.     OffsetRect(&numbersDest[3], 301, 443);
  529.     SetRect(&numbersDest[4], 0, 0, 8, 11);    // score digit 3
  530.     OffsetRect(&numbersDest[4], 309, 443);
  531.     SetRect(&numbersDest[5], 0, 0, 8, 11);    // score digit 4
  532.     OffsetRect(&numbersDest[5], 317, 443);
  533.     SetRect(&numbersDest[6], 0, 0, 8, 11);    // score digit 5
  534.     OffsetRect(&numbersDest[6], 325, 443);
  535.     SetRect(&numbersDest[7], 0, 0, 8, 11);    // score digit 6
  536.     OffsetRect(&numbersDest[7], 333, 443);
  537.     SetRect(&numbersDest[8], 0, 0, 8, 11);    // # of level digit 1
  538.     OffsetRect(&numbersDest[8], 381, 443);
  539.     SetRect(&numbersDest[9], 0, 0, 8, 11);    // # of level digit 2
  540.     OffsetRect(&numbersDest[9], 389, 443);
  541.     SetRect(&numbersDest[10], 0, 0, 8, 11);    // # of level digit 3
  542.     OffsetRect(&numbersDest[10], 397, 443);
  543.     
  544.     SetRect(&playerRects[0], 0, 0, 48, 37);
  545.     OffsetRect(&playerRects[0], 0, 0);
  546.     SetRect(&playerRects[1], 0, 0, 48, 37);
  547.     OffsetRect(&playerRects[1], 0, 37);
  548.     SetRect(&playerRects[2], 0, 0, 48, 37);
  549.     OffsetRect(&playerRects[2], 0, 74);
  550.     SetRect(&playerRects[3], 0, 0, 48, 37);
  551.     OffsetRect(&playerRects[3], 0, 111);
  552.     SetRect(&playerRects[4], 0, 0, 48, 48);
  553.     OffsetRect(&playerRects[4], 0, 148);
  554.     SetRect(&playerRects[5], 0, 0, 48, 48);
  555.     OffsetRect(&playerRects[5], 0, 196);
  556.     SetRect(&playerRects[6], 0, 0, 48, 48);
  557.     OffsetRect(&playerRects[6], 0, 244);
  558.     SetRect(&playerRects[7], 0, 0, 48, 48);
  559.     OffsetRect(&playerRects[7], 0, 292);
  560.     SetRect(&playerRects[8], 0, 0, 48, 37);        // falling bones rt.
  561.     OffsetRect(&playerRects[8], 0, 340);
  562.     SetRect(&playerRects[9], 0, 0, 48, 37);        // falling bones lf.
  563.     OffsetRect(&playerRects[9], 0, 377);
  564.     SetRect(&playerRects[10], 0, 0, 48, 22);    // pile of bones
  565.     OffsetRect(&playerRects[10], 0, 414);
  566.     
  567.     SetRect(&platformSrcRect, 0, 0, 191, 192);
  568.     platformSrcMap = 0L;    // Create pixmap to hold "platform" graphic.
  569.     CreateOffScreenPixMap(&platformSrcRect, &platformSrcMap);
  570.     LoadGraphic(kPlatformPictID);
  571.     for (i = 0; i < 6; i++)
  572.     {
  573.         SetRect(&platformCopyRects[i], 0, 0, 191, 32);
  574.         OffsetRect(&platformCopyRects[i], 0, 32 * i);
  575.     }
  576.     SetRect(&platformCopyRects[6], 233, 190, 424, 222);
  577.     SetRect(&platformCopyRects[7], 0, 105, 191, 137);
  578.     SetRect(&platformCopyRects[8], 449, 105, 640, 137);
  579.                             // These are the platforms.  See diagram for numbering.
  580.     SetRect(&platformRects[0], 206, 424, 433, 438);        //_______________
  581.     SetRect(&platformRects[1], -256, 284, 149, 298);    //
  582.     SetRect(&platformRects[2], 490, 284, 896, 298);        //--3--     --4--
  583.     SetRect(&platformRects[3], -256, 105, 149, 119);    //     --5--
  584.     SetRect(&platformRects[4], 490, 105, 896, 119);        //--1--     --2--
  585.     SetRect(&platformRects[5], 233, 190, 407, 204);        //_____--0--_____
  586.     
  587.     for (i = 0; i < 6; i++)
  588.     {                        // "Hot rects" to sense if player landing on platform.
  589.         touchDownRects[i] = platformRects[i];
  590.         touchDownRects[i].left += 23;
  591.         touchDownRects[i].right -= 23;
  592.         touchDownRects[i].bottom = touchDownRects[i].top;
  593.         touchDownRects[i].top = touchDownRects[i].bottom - 11;
  594.     }
  595.     
  596.     SetRect(&helpSrcRect, 0, 0, 231, 398);
  597.     helpSrcMap = 0L;        // Create pixmap to hold "help screen" graphic.
  598.     CreateOffScreenPixMap(&helpSrcRect, &helpSrcMap);
  599.     LoadGraphic(kHelpPictID);
  600.  
  601. }
  602.  
  603. //--------------------------------------------------------------  ShutItDown
  604.  
  605. #define kFadeSteps        25
  606. #define kFadeStepSize    (100/kFadeSteps)
  607.  
  608. void ShutItDown (void)
  609. {
  610. #if GENERATINGPOWERPC
  611.     long theFinalTick;
  612.     
  613.     DSpContext_FadeGammaOut( NULL, NULL );
  614.     DSpContext_SetState( gTheContext, kDSpContextState_Inactive );
  615.     
  616.     Delay( 30, &theFinalTick );
  617.  
  618.     DSpContext_FadeGammaIn( NULL, NULL );
  619.     
  620.     DSpContext_Release( gTheContext );
  621.     DSpShutdown();
  622.     
  623. #else
  624.     if (wasDepth != WhatsOurDepth())    // Need only switch if wasn't 8-bit.
  625.         SwitchToDepth(wasDepth, TRUE);    // Switch back to out "old" depth.
  626. #endif
  627. }
  628.  
  629. /*
  630. ********************************************************************************
  631. **
  632. ** Name: MyInitAttributes
  633. **
  634. ** Description:
  635. **
  636. **    Initialize a context attributes structure so that there is no garbage
  637. **    data in it.  This is important to do because DS will return an error
  638. **    if some fields are set incorrectly (including the "reserved" fields not
  639. **    being set to zero), and some things can actually cause a crash (such
  640. **    as a bogus color table handle).
  641. **
  642. ********************************************************************************
  643. */
  644. void
  645. MyInitAttributes(
  646.     DSpContextAttributes *inAttributes        /* attr structure to init */
  647. )
  648. {
  649.     if( NULL == inAttributes )
  650.         DebugStr("\pStimpy! You Idiot!");
  651.         
  652.     inAttributes->frequency                    = 0;
  653.     inAttributes->displayWidth                = 0;
  654.     inAttributes->displayHeight                = 0;
  655.     inAttributes->reserved1                    = 0;
  656.     inAttributes->reserved2                    = 0;
  657.     inAttributes->colorNeeds                = 0;
  658.     inAttributes->colorTable                = NULL;
  659.     inAttributes->contextOptions            = 0;
  660.     inAttributes->backBufferDepthMask        = 0;
  661.     inAttributes->displayDepthMask            = 0;
  662.     inAttributes->backBufferBestDepth        = 0;
  663.     inAttributes->displayBestDepth            = 0;
  664.     inAttributes->pageCount                    = 0;
  665.     inAttributes->gameMustConfirmSwitch        = false;
  666.     inAttributes->reserved3[0]                = 0;
  667.     inAttributes->reserved3[1]                = 0;
  668.     inAttributes->reserved3[2]                = 0;
  669.     inAttributes->reserved3[3]                = 0;
  670. }
  671.